
import config
from proxyCanvas import Canvas
import infoSchema

schema1 = {
    'Parent': [
        {'name':'name', 'typeName': 'str', 'isIdentifier':True},
        {'name':'BD', 'typeName': 'str'},
        {'name':'phone', 'typeName': 'str'},
        ],
    'Child': [
        {'name':'name', 'typeName': 'str', 'isIdentifier':True},
        {'name':'BD', 'typeName': 'str'},
        {'name':'mom', 'typeName': 'Parent', 'isIdentifier':True},
        ],
}

def test1(outfile="/tmp/c1.html", schema1=schema1):
    c = Canvas()
    cfg = config.Configuration()
    S1 = infoSchema.schemaFromJsonValue(schema1)
    S1.dumpToCanvas(c, cfg)
    c.dumpTestHtml(outfile)
    print "test schema dumped to", repr(outfile)

schema2 = {
    'Proj': [ 
        {'name':'pnum','typeName': 'int', 'isIdentifier':True} ,
        {'name':'mgr','typeName': 'Emp'},
        {'name': 'partOf', 'typeName':'Proj'},
        {'name': 'within', 'typeName':'Dept'},
        ],
    'Status': [ 
        {'name':'category','typeName': 'str', 'isIdentifier':True} ,
        {'name':'minsalary','typeName': 'currency'},
        {'name':'maxsalary','typeName': 'currency'},
        ],
    'Dept': [ 
        {'name':'dnum','typeName': 'int', 'isIdentifier':True} , 
        {'name':'mgr','typeName': 'Emp'}
        ],
    'Emp': [ 
        {'name':'enum','typeName': 'int', 'isIdentifier': True} ,
        {'name':'category','typeName': 'Status'}
        ],
    'WorksOn': [
        {'name':'worker','typeName': 'Emp', 'isIdentifier':True} ,
        {'name':'activity','typeName': 'Proj', 'isIdentifier':True} ,
        ],
    'WorksFor': [
        {'name':'worker','typeName': 'Emp', 'isIdentifier':True} ,
        {'name':'group','typeName': 'Dept', 'isIdentifier':True} ,
        ],
    }

def test2(outfile="/tmp/c2.html"):
    test1(outfile, schema2)

if __name__=="__main__":
    test2()
